﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Arthus.Brendovi
{
    public partial class brendoviForma : Form
    {
        private int idBrenda;
        public brendoviForma()
        {
            InitializeComponent();
        }

        Brend brendObjekat = null;

        private void brendoviForma_Load(object sender, EventArgs e)
        {
            brendObjekat = new Brend();
            brendObjekat.PopuniListBox(listBoxBrendovi);
            brendObjekat.PopuniKontroleNaOsnovuIdBrenda(idBrenda, textBoxOznaka, textBoxNaziv, textBoxNaziv2);
            listBoxBrendovi.SelectedIndex = 0;
        }

        private void brendoviForma_Activated(object sender, EventArgs e)
        {
            brendObjekat = new Brend();
            brendObjekat.PopuniListBox(listBoxBrendovi);
            brendObjekat.PopuniKontroleNaOsnovuIdBrenda(idBrenda, textBoxOznaka, textBoxNaziv, textBoxNaziv2);
            idBrenda = Convert.ToInt32(listBoxBrendovi.SelectedItem.ToString().Split('.')[0]);
        }

        private void buttonZatvori_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void TABKaoENTER(KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                e.SuppressKeyPress = true;
                SelectNextControl(ActiveControl, true, true, true, true);
            }
        }
        private void textBoxOznaka_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxNaziv_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }
        private void textBoxNaziv2_KeyDown(object sender, KeyEventArgs e)
        {
            TABKaoENTER(e);
        }

        private void VratiSveNaPocetak() {
            textBoxOznaka.Text = "";
            textBoxNaziv.Text = "";
            textBoxNaziv2.Text = "";
        }

        private void buttonDodaj_Click(object sender, EventArgs e)
        {
            brendObjekat = new Brend();
            brendObjekat.DodajBrend(textBoxOznaka, textBoxNaziv, textBoxNaziv2);
            VratiSveNaPocetak();
            textBoxOznaka.Focus();
        }

        private void listBoxBrendovi_SelectedIndexChanged(object sender, EventArgs e)
        {
            idBrenda = Convert.ToInt32(listBoxBrendovi.SelectedItem.ToString().Split('.')[0]);
            brendObjekat = new Brend();
            brendObjekat.PopuniKontroleNaOsnovuIdBrenda(idBrenda, textBoxOznaka, textBoxNaziv, textBoxNaziv2);
        }

        private void buttonIzmeni_Click(object sender, EventArgs e)
        {
            brendObjekat = new Brend();
            brendObjekat.IzmeniBrend(idBrenda, textBoxOznaka, textBoxNaziv, textBoxNaziv2);
        }

        private void buttonObrisi_Click(object sender, EventArgs e)
        {
            brendObjekat = new Brend();
            brendObjekat.ObrisiBrend(idBrenda);
        }
    }
}
